<?php
/**
 * OtherController.class.php
 * @package Controller
 * @version $Id: IndexController.class.php 1.0 2016-11-07 22:18:13Z $
 */
class OtherController extends BaseController{

     public function faqAction(){
         $this -> display();
     }

    public function joinAction(){
        $this -> display();
    }

    public function addSuppliersAction(){
        $model = Controller::createMode(BaseController::$default_db,'t_26_suppliers_join');
        $name = $this->get("name") ? $this->get("name")  : $this->post("name") ;
        $address = $this->get("address") ? $this->get("address")  : $this->post("address") ;
        $contact_name = $this->get("contact_name") ? $this->get("contact_name")  : $this->post("contact_name") ;
        $contact_tel = $this->get("contact_tel") ? $this->get("contact_tel")  : $this->post("contact_tel") ;
        $site_url = $this->get("site_url") ? $this->get("site_url")  : $this->post("site_url") ;
        $license_no = $this->get("license_no") ? $this->get("license_no")  : $this->post("license_no") ;
        $login_username = $this->get("login_username") ? $this->get("login_username")  : $this->post("login_username") ;
        $login_password = $this->get("login_password") ? $this->get("login_password")  : $this->post("login_password") ;
        $s_remark = $this->get("remark") ? $this->get("remark")  : $this->post("remark") ;
         $image = $this->get("image") ? $this->get("image")  : $this->post("image") ;
        $scope= $this->get("scope") ? $this->get("scope")  : $this->post("scope") ;
        $file_name = $this->get("file_name") ? $this->get("file_name")  : $this->post("file_name") ;
        $file_names = explode(",", $file_name);
        $supper_info=$model->select();
        foreach($supper_info as $key => $row){
           if( strtolower($row['license_no'])== strtolower($license_no)){
               $result = array();
               $result['code'] = 200;
               $result['msg'] = '当前营业执照号已存在，正在审核中';
               echo json_encode($result, true) ;exit;
           }
        }

        $params=array(
            'name'=>$name,
            'address'=>$address,
            'contact_name'=>$contact_name,
            'contact_tel'=>$contact_tel,
            'site_url'=>$site_url,
            'license_no'=>$license_no,
            'login_username'=>$login_username,
            'login_password'=>md5($login_password),
            'image'=>$image,
            'scope'=>$scope,
            'remark'=>$s_remark,
        );

        $m_id = $model->insert($params,true);
        if($m_id){
            $attach_model = Controller::createMode(BaseController::$default_db,'t_26_suppliers_join_attach');
            foreach($file_names as $key => $row){
                $result = $attach_model->insert(array(
                    'id'=>$key,
                    'm_id'=>$m_id,
                    'file_name'=>$row,
                    'insert_dt'=>date("Y-m-d H:i:s"),
                ));
            }
        if($result){
            $result = array();
            $result['code'] = 200;
            $result['msg'] = '谢谢! 您的信息已经保存，请耐心等待审核!';
            echo json_encode($result, true) ;exit;
        }

        } else {
            $result = array();
            $result['code'] = 203;
            echo json_encode($result, true) ;exit;
        }
    }

}
